home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 329 / x6502.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-18  |  9.9 KB  |  361 lines

  1.  
  2. /****************************************************************************
  3.  
  4.     X6502.H  
  5.  
  6.     - extern declarations of opcode handler routines
  7.  
  8.     01/23/88 created
  9.  
  10.     06/09/88 19:50
  11.  
  12. ****************************************************************************/
  13.  
  14. /* exit codes from interpreter */
  15. #define EXIT_BREAK      0
  16. #define EXIT_INVALID    1
  17. #define EXIT_ALTKEY     2
  18.  
  19. /* opcode for RTS */
  20. #define OP_RTS      0x4E75
  21.  
  22. /* opcode to jump to interrupt vector */
  23. #define OP_INT      0x60E8
  24.  
  25. /* opcode for JMP long */
  26. #define OP_JMP      0x4EF9
  27.  
  28. /* first 2 words of dispatcher */
  29. #define OP_EMUL     0x1A99
  30.  
  31. /* status bits of the P register: (6502)  NV_BDIZC */
  32.  
  33. #define NBIT 0x80
  34. #define VBIT 0x40
  35. #define BBIT 0x10
  36. #define DBIT 0x08
  37. #define IBIT 0x04
  38. #define ZBIT 0x02
  39. #define CBIT 0x01
  40.  
  41. /* status bits of the CCR register: (68000)  ___XNZVC */
  42.  
  43. #define BITV 0x02
  44. #define BITN 0x08
  45. #define BITZ 0x04
  46. #define BITC 0x01
  47. #define BITX 0x10
  48.  
  49. /* convert P register NV_BDIZC to CCR register BDIXNZVC */
  50. #define P_to_ST         \
  51.     move.b  bRegP(arEMUL),drDATA \
  52.     btst    #4,drDATA   \
  53.     sne     bB(arEMUL)  \
  54.     btst    #3,drDATA   \
  55.     sne     drST \
  56.     ext.w   drST \
  57.     ext.l   drST \
  58.     btst    #2,drDATA   \
  59.     sne     bI(arEMUL)  \
  60.     btst    #6,drDATA   \
  61.     sne     bV(arEMUL)  \
  62.     btst    #0,drDATA   \
  63.     sne     drC  \
  64.     andi.b  #ZBIT,drDATA \
  65.     seq     drST   \
  66.     andi.b  #0x7F,drST \
  67.     move.b  bRegP(arEMUL),drDATA \
  68.     andi.b  #0x80,drDATA \
  69.     or.b    drDATA,drST \
  70.     ext.w   drST
  71.  
  72. /* convert CCR register BDIXNZVC to P register NV_BDIZC */
  73. #define ST_to_P         \
  74.     move.b  bB(arEMUL),drEA \
  75.     andi.w  #BBIT,drEA  \
  76.     tst.l   drST \
  77.     smi     drDATA \
  78.     andi.w  #DBIT,drDATA \
  79.     or.b    drDATA,drEA \
  80.     move.b  bI(arEMUL),drDATA \
  81.     andi.w  #IBIT,drDATA \
  82.     or.b    drDATA,drEA \
  83.     move.b  bV(arEMUL),drDATA \
  84.     andi.w  #VBIT,drDATA \
  85.     or.b    drDATA,drEA \
  86.     move.b  drC,drDATA \
  87.     andi.w  #CBIT,drDATA \
  88.     or.b    drDATA,drEA \
  89.     move.b  drST,drDATA \
  90.     seq     drDATA   \
  91.     andi.b  #ZBIT,drDATA \
  92.     or.b    drDATA,drEA \
  93.     lsr.w   #1,drST \
  94.     andi.b  #0x80,drST \
  95.     or.b    drST,drEA \
  96.     ori.b   #0x20,drEA  \
  97.     move.b  drEA,bRegP(arEMUL)
  98.  
  99. /* data register definitions of 6502 registers */
  100.  
  101. #define drDATA  D0
  102. #define drA     D1
  103. #define drX     D2
  104. #define drY     D3
  105. #define drSP    D4
  106. #define drC     D5
  107. #define drST    D6
  108. #define drEA    D7
  109.  
  110. /* pointer to mem[ea] and otherwise all purpose register*/
  111. #define arEA    A0
  112.  
  113. /* pointer to current 6502 opcode */
  114. #define arPC    A1
  115.  
  116. /* pointer to the dispatcher, from which all other addresses are calced */
  117. #define arEMUL  A2
  118.  
  119. /* pointer to array of read status bytes */
  120. #define arRSTAT A3
  121.  
  122. /* pointer to array of write status bytes */
  123. #define arWSTAT A4
  124.  
  125. /* arEMUL + 4, pointer to self modifying jump vector in dispatcher */
  126. #define arEMVEC A5
  127.  
  128. /* pointer to the frame (local variables) */
  129. #define LOCAL   A6
  130.  
  131. /* the stack pointer, for some reason, not defined by Megamax */
  132. #define SP      A7
  133.  
  134. /* quickly save and restore 6502 variables */
  135. #define SAVEREGS    movem.l D0-D7/A0-A5,-(SP)
  136. #define LOADREGS    movem.l (SP)+,D0-D7/A0-A5
  137.  
  138. /* finished executing an opcode, go to dispatch routine */
  139. #define DISPATCH jmp (arEMUL)
  140.  
  141. #define UNUSED   jmp (arEMUL)
  142.  
  143. /* Effective Address calculation macros */
  144.  
  145. /* (zp,X) 44 cycles */
  146. /* dc.w    0x0F08,0x0001 ; movep.w 1(arEA),drEA */
  147. #define EA_zpXind \
  148.     clr.w   drEA         \
  149.     move.b  (arPC)+,drEA \
  150.     add.b   drX,drEA     \
  151.     move.l  drEA,arEA    \
  152.     dc.w    0x0F08,0x0001 \
  153.     move.b  (arEA),drEA  \
  154.     move.l  drEA,arEA
  155.  
  156. /* zp 16 cycles */
  157. #define EA_zp \
  158.     clr.w   drEA \
  159.     move.b  (arPC)+,drEA \
  160.     move.l  drEA,arEA
  161.  
  162. /* same as zp, except used before a LDA to save 4 cycles */
  163. #define EA_Azp \
  164.     move.b  (arPC)+,drA \
  165.     move.l  drA,arEA
  166.  
  167. /* same as zp, except used before a LDX to save 4 cycles */
  168. #define EA_Xzp \
  169.     move.b  (arPC)+,drX \
  170.     move.l  drX,arEA
  171.  
  172. /* same as zp, except used before a LDY to save 4 cycles */
  173. #define EA_Yzp \
  174.     move.b  (arPC)+,drY \
  175.     move.l  drY,arEA
  176.  
  177. /* abs 32 cycles */
  178. /* dc.w    0x0F09,0x0001  ; movep.w 1(arPC),drEA */
  179. #define EA_abs \
  180.     dc.w    0x0F09,0x0001 \
  181.     move.b  (arPC),drEA \
  182.     addq.w  #2,arPC \
  183.     move.l  drEA,arEA
  184.  
  185. /* abs,X 36 cycles */
  186. /* dc.w    0x0F09,0x0001   ; movep.w 1(arPC),drEA */
  187. #define EA_absX \
  188.     dc.w    0x0F09,0x0001 \
  189.     move.b  (arPC),drEA \
  190.     addq.w  #2,arPC \
  191.     add.w   drX,drEA \
  192.     move.l  drEA,arEA
  193.  
  194. /* abs,Y 36 cycles */
  195. /* dc.w    0x0F09,0x0001   ; movep.w 1(arPC),drEA */
  196. #define EA_absY \
  197.     dc.w    0x0F09,0x0001 \
  198.     move.b  (arPC),drEA \
  199.     addq.w  #2,arPC \
  200.     add.w   drY,drEA \
  201.     move.l  drEA,arEA
  202.  
  203. /* (zp),Y 44 cycles */
  204. /* dc.w    0x0F08,0x0001   ; movep.w 1(arEA),drEA */
  205. #define EA_zpYind \
  206.     clr.w   drEA \
  207.     move.b  (arPC)+,drEA \
  208.     move.l  drEA,arEA \
  209.     dc.w    0x0F08,0x0001 \
  210.     move.b  (arEA),drEA \
  211.     add.w   drY,drEA \
  212.     move.l  drEA,arEA
  213.  
  214. /* zp,X 20 cycles */
  215. #define EA_zpX \
  216.     clr.w   drEA \
  217.     move.b  (arPC)+,drEA \
  218.     add.b   drX,drEA \
  219.     move.l  drEA,arEA
  220.  
  221. /* zp,X 16 cycles, before a LDA */
  222. #define EA_AzpX \
  223.     move.b  (arPC)+,drA \
  224.     add.b   drX,drA \
  225.     move.l  drA,arEA
  226.  
  227. /* zp,Y 20 cycles */
  228. #define EA_zpY \
  229.     clr.w   drEA \
  230.     move.b  (arPC)+,drEA \
  231.     add.b   drY,drEA \
  232.     move.l  drEA,arEA
  233.  
  234. /* $6704 (beq.s *+4) is used because Megamax doesn't have local labels */
  235. #define ReadService \
  236.     cmpi.w  #0xC000,drEA \
  237.     dc.w    0x650A \
  238.     move.b  0(arRSTAT,drEA),drDATA \
  239.     dc.w    0x6704  \
  240.     jsr     lReadDisp(arEMUL)
  241.  
  242. #define WriteService \
  243.     move.b  0(arWSTAT,drEA),drDATA \
  244.     dc.w    0x6A06 \
  245.     move.w  drST,-(SP) \
  246.     jmp     lWriteDisp(arEMUL)
  247.  
  248. #define WriteAService \
  249.     move.b  0(arWSTAT,drEA),drDATA \
  250.     dc.w    0x6A06  \
  251.     move.w  drA,-(SP) \
  252.     jmp     lWriteDisp(arEMUL)
  253.  
  254. #define WriteXService \
  255.     move.b  0(arWSTAT,drEA),drDATA \
  256.     dc.w    0x6A06  \
  257.     move.w  drX,-(SP) \
  258.     jmp     lWriteDisp(arEMUL)
  259.  
  260. #define WriteYService \
  261.     move.b  0(arWSTAT,drEA),drDATA \
  262.     dc.w    0x6706  \
  263.     move.w  drY,-(SP) \
  264.     jmp     lWriteDisp(arEMUL)
  265.  
  266. /* offsets of assembler level variables, offset from arEMUL */
  267.  
  268. #define cbGLOBALS   162
  269.  
  270. #define JumpVecs    -162
  271. #define Jump0       -162
  272. #define Jump1       -158
  273. #define Jump2       -154
  274. #define Jump3       -150
  275. #define Jump4       -146
  276.  
  277. #define SaveRegs    -98
  278.  
  279. #define bNMI        -42
  280. #define bIRQ        -41
  281. #define bIRQmask    -40
  282. #define bB          -39
  283. #define xxxbD          -38
  284. #define bI          -37
  285. #define bV          -36
  286. #define bCX         -35
  287.  
  288. /* these guys pass the 6502 registers back and forth to the monitor */
  289. #define bRegA       -34
  290. #define bRegX       -33
  291. #define bRegY       -32
  292. #define bRegP       -31
  293. #define wRegSP      -30
  294. #define wRegPC      -28
  295. #define wEA         -26
  296.  
  297. /* when exiting interpreter, this code tells us why */
  298. #define wExitCode   -24
  299.  
  300. #define lInterrupt  -22
  301. #define lIntVec     -20
  302.  
  303. #define lWriteDisp  -16
  304. #define lReadDisp   -8
  305.  
  306. #define cbDISPATCH  6
  307.  
  308. /* these offsets give the starting byte of each routine in the page */
  309. /* opcodes are at byte 6, read routines as byte $80, in opcode 0 to $7F */
  310. /* and write routines also at byte $80, in opcodes $80 to $FF */
  311. #define iOpcodes    6
  312. #define iRead       0x80
  313. #define iWrite      0x8080
  314.  
  315. extern int (*vec_6502[257])();  /* pointer to 256 opcode routines and dummy */
  316.  
  317. extern Lemul(), Lglobals();
  318.  
  319. extern RegA4();
  320.  
  321. /* when emulation is about to being, these routines hook in VBIs, etc... */
  322. extern (*pHookIn)(), (*pUnHook)();
  323.  
  324. /* tell Megamax that the emulation routines will be found in inline code: */
  325. extern
  326. op00(), op01(), op02(), op03(), op04(), op05(), op06(), op07(),
  327. op08(), op09(), op0A(), op0B(), op0C(), op0D(), op0E(), op0F(),
  328. op10(), op11(), op12(), op13(), op14(), op15(), op16(), op17(),
  329. op18(), op19(), op1A(), op1B(), op1C(), op1D(), op1E(), op1F(),
  330. op20(), op21(), op22(), op23(), op24(), op25(), op26(), op27(),
  331. op28(), op29(), op2A(), op2B(), op2C(), op2D(), op2E(), op2F(),
  332. op30(), op31(), op32(), op33(), op34(), op35(), op36(), op37(),
  333. op38(), op39(), op3A(), op3B(), op3C(), op3D(), op3E(), op3F(),
  334. op40(), op41(), op42(), op43(), op44(), op45(), op46(), op47(),
  335. op48(), op49(), op4A(), op4B(), op4C(), op4D(), op4E(), op4F(),
  336. op50(), op51(), op52(), op53(), op54(), op55(), op56(), op57(),
  337. op58(), op59(), op5A(), op5B(), op5C(), op5D(), op5E(), op5F(),
  338. op60(), op61(), op62(), op63(), op64(), op65(), op66(), op67(),
  339. op68(), op69(), op6A(), op6B(), op6C(), op6D(), op6E(), op6F(),
  340. op70(), op71(), op72(), op73(), op74(), op75(), op76(), op77(),
  341. op78(), op79(), op7A(), op7B(), op7C(), op7D(), op7E(), op7F(),
  342. op80(), op81(), op82(), op83(), op84(), op85(), op86(), op87(),
  343. op88(), op89(), op8A(), op8B(), op8C(), op8D(), op8E(), op8F(),
  344. op90(), op91(), op92(), op93(), op94(), op95(), op96(), op97(),
  345. op98(), op99(), op9A(), op9B(), op9C(), op9D(), op9E(), op9F(),
  346. opA0(), opA1(), opA2(), opA3(), opA4(), opA5(), opA6(), opA7(),
  347. opA8(), opA9(), opAA(), opAB(), opAC(), opAD(), opAE(), opAF(),
  348. opB0(), opB1(), opB2(), opB3(), opB4(), opB5(), opB6(), opB7(),
  349. opB8(), opB9(), opBA(), opBB(), opBC(), opBD(), opBE(), opBF(),
  350. opC0(), opC1(), opC2(), opC3(), opC4(), opC5(), opC6(), opC7(),
  351. opC8(), opC9(), opCA(), opCB(), opCC(), opCD(), opCE(), opCF(),
  352. opD0(), opD1(), opD2(), opD3(), opD4(), opD5(), opD6(), opD7(),
  353. opD8(), opD9(), opDA(), opDB(), opDC(), opDD(), opDE(), opDF(),
  354. opE0(), opE1(), opE2(), opE3(), opE4(), opE5(), opE6(), opE7(),
  355. opE8(), opE9(), opEA(), opEB(), opEC(), opED(), opEE(), opEF(),
  356. opF0(), opF1(), opF2(), opF3(), opF4(), opF5(), opF6(), opF7(),
  357. opF8(), opF9(), opFA(), opFB(), opFC(), opFD(), opFE(), opFF(),
  358. opXX();
  359.  
  360.  
  361.